// 操作数据--获取请求的数据,然后调用 mutations内的方法实现数据的修改
import * as types from './mutations-types';
import {ModelDesignApi} from "@/api/modeldesign";

//获取模板的配置信息--所谓的节目信息
export const setTemplateList = async function ({commit, state}, data) {
    let result = Object();
    try {
        const resp = await ModelDesignApi.getPageList(data);
        if ((resp.code) === 200) {
            let dataInfo = (resp.rows);
            let dataInfos = Object();
            Reflect.set(dataInfos, "pageIndex", parseInt(data.pageNum));
            Reflect.set(dataInfos, "pageSize", parseInt(data.pageSize));
            Reflect.set(dataInfos, "total", parseInt(resp.total));
            Reflect.set(dataInfos, "pagesTotal", Math.round(parseInt(resp.total)/parseInt(data.pageSize)));
            Reflect.set(dataInfos, "list", dataInfo || Array());
            Reflect.set(result, "status", true);
            Reflect.set(result, "result", dataInfos);
            commit(types.SET_TEMPLATE_LIST_INFO, dataInfos);
            commit(types.SET_TEMPLATE_LIST_PARAMS_INFO, data);
        } else {
            Reflect.set(result, 'state', false);
        }
    } catch (err) {
        Reflect.set(result, 'state', false);
    }
    return result
};

export const setTemplateListParams = async function ({commit, state}, data) {
    commit(types.SET_TEMPLATE_LIST_PARAMS_INFO, data);
};


// 类目删除
export const setTemplateDelete = async function ({commit, state}, data) {
    let result = Object();
    try {
        const resp = await ModelDesignApi.remove(data);
        if ((resp.code) === 200) {
            Reflect.set(result, "status", true);
        } else {
            Reflect.set(result, "status", false);
        }
    } catch (err) {
        Reflect.set(result, 'state', false);
    }
    return result;
};


